import java.awt.*;

import javax.swing.*;


public class PawnPanel extends JPanel
{
	enum Move {left, up, right, down}

	private ImageIcon image;
	private int curLocation; // current location on the game board
	private int newLocation,newLocationX,newLocationY; // new location to move to
	private int playerNum;
	private Move direction; // 1 - left, 2 - up, 3 - right, 4 - down
	private int[] placementX, placementY;
	
	public PawnPanel(String name)
	{
		setPreferredSize(new Dimension(495,495));
		setOpaque(false);
		curLocation = 0;
		newLocation = 0;
		playerNum = 0;
		image = new ImageIcon("./logos/pawn_" + name + "_small.jpg");
		direction = Move.left;
	}
	
	public void initializePlacementArray()
	{
		placementX = new int[40];
		placementY = new int[40];
		if(playerNum == 1)
		{
			placementX[0] =630;
			placementX[1] =541;
			placementX[2] =486;
			placementX[3] =431;
			placementX[4] =376;
			placementX[5] =321;
			placementX[6] =266;
			placementX[7] =211;
			placementX[8] =156;
			placementX[9] =101;
			placementX[10]=12;
			placementX[11]=12;
			placementX[12]=12;
			placementX[13]=12;
			placementX[14]=12;
			placementX[15]=12;
			placementX[16]=12;
			placementX[17]=12;
			placementX[18]=12;
			placementX[19]=12;
			placementX[20]=12;
			placementX[21]=101;
			placementX[22]=156;
			placementX[23]=211;
			placementX[24]=266;
			placementX[25]=321;
			placementX[26]=376;
			placementX[27]=431;
			placementX[28]=486;
			placementX[29]=541;
			placementX[30]=630;
			placementX[31]=630;
			placementX[32]=630;
			placementX[33]=630;
			placementX[34]=630;
			placementX[35]=630;
			placementX[36]=630;
			placementX[37]=630;
			placementX[38]=630;
			placementX[39]=630;
			
			placementY[0] =630;
			placementY[1] =630;
			placementY[2] =630;
			placementY[3] =630;
			placementY[4] =630;
			placementY[5] =630;
			placementY[6] =630;
			placementY[7] =630;
			placementY[8] =630;
			placementY[9] =630;
			placementY[10]=630;
			placementY[11]=541;
			placementY[12]=486;
			placementY[13]=431;
			placementY[14]=376;
			placementY[15]=321;
			placementY[16]=266;
			placementY[17]=211;
			placementY[18]=156;
			placementY[19]=101;
			placementY[20]=12;
			placementY[21]=12;
			placementY[22]=12;
			placementY[23]=12;
			placementY[24]=12;
			placementY[25]=12;
			placementY[26]=12;
			placementY[27]=12;
			placementY[28]=12;
			placementY[29]=12;
			placementY[30]=12;
			placementY[31]=101;
			placementY[32]=156;
			placementY[33]=211;
			placementY[34]=266;
			placementY[35]=321;
			placementY[36]=376;
			placementY[37]=431;
			placementY[38]=486;
			placementY[39]=541;
		}
		else if(playerNum == 2)
		{
			placementX[0] =658;
			placementX[1] =569;
			placementX[2] =514;
			placementX[3] =459;
			placementX[4] =404;
			placementX[5] =349;
			placementX[6] =294;
			placementX[7] =239;
			placementX[8] =184;
			placementX[9] =129;
			placementX[10]=40;
			placementX[11]=40;
			placementX[12]=40;
			placementX[13]=40;
			placementX[14]=40;
			placementX[15]=40;
			placementX[16]=40;
			placementX[17]=40;
			placementX[18]=40;
			placementX[19]=40;
			placementX[20]=40;
			placementX[21]=129;
			placementX[22]=184;
			placementX[23]=239;
			placementX[24]=294;
			placementX[25]=349;
			placementX[26]=404;
			placementX[27]=459;
			placementX[28]=514;
			placementX[29]=569;
			placementX[30]=658;
			placementX[31]=658;
			placementX[32]=658;
			placementX[33]=658;
			placementX[34]=658;
			placementX[35]=658;
			placementX[36]=658;
			placementX[37]=658;
			placementX[38]=658;
			placementX[39]=658;
			
			placementY[0] =630;
			placementY[1] =630;
			placementY[2] =630;
			placementY[3] =630;
			placementY[4] =630;
			placementY[5] =630;
			placementY[6] =630;
			placementY[7] =630;
			placementY[8] =630;
			placementY[9] =630;
			placementY[10]=630;
			placementY[11]=541;
			placementY[12]=486;
			placementY[13]=431;
			placementY[14]=376;
			placementY[15]=321;
			placementY[16]=266;
			placementY[17]=211;
			placementY[18]=156;
			placementY[19]=101;
			placementY[20]=12;
			placementY[21]=12;
			placementY[22]=12;
			placementY[23]=12;
			placementY[24]=12;
			placementY[25]=12;
			placementY[26]=12;
			placementY[27]=12;
			placementY[28]=12;
			placementY[29]=12;
			placementY[30]=12;
			placementY[31]=101;
			placementY[32]=156;
			placementY[33]=211;
			placementY[34]=266;
			placementY[35]=321;
			placementY[36]=376;
			placementY[37]=431;
			placementY[38]=486;
			placementY[39]=541;
		}
		else if(playerNum == 3)
		{
			placementX[0] =630;
			placementX[1] =541;
			placementX[2] =486;
			placementX[3] =431;
			placementX[4] =376;
			placementX[5] =321;
			placementX[6] =266;
			placementX[7] =211;
			placementX[8] =156;
			placementX[9] =101;
			placementX[10]=12;
			placementX[11]=12;
			placementX[12]=12;
			placementX[13]=12;
			placementX[14]=12;
			placementX[15]=12;
			placementX[16]=12;
			placementX[17]=12;
			placementX[18]=12;
			placementX[19]=12;
			placementX[20]=12;
			placementX[21]=101;
			placementX[22]=156;
			placementX[23]=211;
			placementX[24]=266;
			placementX[25]=321;
			placementX[26]=376;
			placementX[27]=431;
			placementX[28]=486;
			placementX[29]=541;
			placementX[30]=630;
			placementX[31]=630;
			placementX[32]=630;
			placementX[33]=630;
			placementX[34]=630;
			placementX[35]=630;
			placementX[36]=630;
			placementX[37]=630;
			placementX[38]=630;
			placementX[39]=630;
			
			placementY[0] =658;
			placementY[1] =658;
			placementY[2] =658;
			placementY[3] =658;
			placementY[4] =658;
			placementY[5] =658;
			placementY[6] =658;
			placementY[7] =658;
			placementY[8] =658;
			placementY[9] =658;
			placementY[10]=658;
			placementY[11]=569;
			placementY[12]=514;
			placementY[13]=459;
			placementY[14]=404;
			placementY[15]=349;
			placementY[16]=294;
			placementY[17]=239;
			placementY[18]=184;
			placementY[19]=129;
			placementY[20]=40;
			placementY[21]=40;
			placementY[22]=40;
			placementY[23]=40;
			placementY[24]=40;
			placementY[25]=40;
			placementY[26]=40;
			placementY[27]=40;
			placementY[28]=40;
			placementY[29]=40;
			placementY[30]=40;
			placementY[31]=129;
			placementY[32]=184;
			placementY[33]=239;
			placementY[34]=294;
			placementY[35]=349;
			placementY[36]=404;
			placementY[37]=459;
			placementY[38]=514;
			placementY[39]=569;
		}
		else if(playerNum==4)
		{
			placementX[0] =658;
			placementX[1] =569;
			placementX[2] =514;
			placementX[3] =459;
			placementX[4] =404;
			placementX[5] =349;
			placementX[6] =294;
			placementX[7] =239;
			placementX[8] =184;
			placementX[9] =129;
			placementX[10]=40;
			placementX[11]=40;
			placementX[12]=40;
			placementX[13]=40;
			placementX[14]=40;
			placementX[15]=40;
			placementX[16]=40;
			placementX[17]=40;
			placementX[18]=40;
			placementX[19]=40;
			placementX[20]=40;
			placementX[21]=129;
			placementX[22]=184;
			placementX[23]=239;
			placementX[24]=294;
			placementX[25]=349;
			placementX[26]=404;
			placementX[27]=459;
			placementX[28]=514;
			placementX[29]=569;
			placementX[30]=658;
			placementX[31]=658;
			placementX[32]=658;
			placementX[33]=658;
			placementX[34]=658;
			placementX[35]=658;
			placementX[36]=658;
			placementX[37]=658;
			placementX[38]=658;
			placementX[39]=658;

			placementY[0] =658;
			placementY[1] =658;
			placementY[2] =658;
			placementY[3] =658;
			placementY[4] =658;
			placementY[5] =658;
			placementY[6] =658;
			placementY[7] =658;
			placementY[8] =658;
			placementY[9] =658;
			placementY[10]=658;
			placementY[11]=569;
			placementY[12]=514;
			placementY[13]=459;
			placementY[14]=404;
			placementY[15]=349;
			placementY[16]=294;
			placementY[17]=239;
			placementY[18]=184;
			placementY[19]=129;
			placementY[20]=40;
			placementY[21]=40;
			placementY[22]=40;
			placementY[23]=40;
			placementY[24]=40;
			placementY[25]=40;
			placementY[26]=40;
			placementY[27]=40;
			placementY[28]=40;
			placementY[29]=40;
			placementY[30]=40;
			placementY[31]=129;
			placementY[32]=184;
			placementY[33]=239;
			placementY[34]=294;
			placementY[35]=349;
			placementY[36]=404;
			placementY[37]=459;
			placementY[38]=514;
			placementY[39]=569;
		}
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);

		g.drawImage(image.getImage(),0,0,null);
		image.paintIcon(this, g, 0, 0);
	}
	
	public int getCurrentBoardLocation()
	{
		return curLocation;
	}
	
	public void setNewBoardLocation(int loc)
	{
		newLocation = loc % 40;
		newLocationX=placementX[newLocation];
		newLocationY=placementY[newLocation];
	}
	
	public int getNewLocationX()
	{
		return newLocationX;
	}
	
	public int getNewLocationY()
	{
		return newLocationY;
	}
	
	public int getNewBoardLocation()
	{
		return newLocation;
	}
	
	public void setPlayerNum(int num)
	{
		playerNum = num;
	}
	
	public String getDirection()
	{
		if(direction == Move.left)
		{
			return "left";
		}
		else if(direction == Move.right)
		{
			return "right";
		}
		else if(direction == Move.up)
		{
			return "up";
		}
		else
		{
			return "down";
		}
	}
	
	public void setDirection(String dir)
	{
		if(dir == "left")
		{
			direction = Move.left;
		}
		else if(dir == "right")
		{
			direction = Move.right;
		}
		else if(dir == "up")
		{
			direction = Move.up;
		}
		else
			direction = Move.down;
		
	}
}
